<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h3>随便看看</h3>
    <button class="b1">1</button><button class="b2">2</button><br>
    <button class="b3">3</button><button class="b4">4</button><br>
    <button class="b5">5</button><button class="b6">6</button><br>
</body>
</html>
<script>
    var an= document.querySelectorAll("button")
    for(i=0;i<an.length;i++){
        an[i].onclick=function(){
            for(i=0;i<an.length;i++){
                an[i].style.backgroundColor=''
            }
            this.style.backgroundColor='red'
        }
    }
</script>